package com.tanhua.server.controller;

<<<<<<< HEAD
=======
import com.tanhua.server.service.CommentService;
>>>>>>> acc7004 (第4天到第8天)
import com.tanhua.server.service.MomentService;
import com.tanhua.vo.MomentVo;
import com.tanhua.vo.PageResult;
import com.tanhua.vo.PublishVo;
import org.springframework.beans.factory.annotation.Autowired;
<<<<<<< HEAD
=======
import org.springframework.beans.factory.annotation.Value;
>>>>>>> acc7004 (第4天到第8天)
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @version 1.0
 * @author： xtr
<<<<<<< HEAD
 * @date： 2021-03-10 20:27
=======
 * @date： 2021-03-13 19:20
>>>>>>> acc7004 (第4天到第8天)
 */
@RestController
@RequestMapping("/movements")
public class MomentController {

    @Autowired
    private MomentService momentService;

<<<<<<< HEAD
    @PostMapping
    public ResponseEntity postMoment(PublishVo publishVo, MultipartFile[] imageContent){
        momentService.postMoment(publishVo,imageContent);
        return ResponseEntity.ok(null);
    }

    @GetMapping
    public ResponseEntity queryFriendPublishList(@RequestParam(value = "page",defaultValue = "1") long page,
                                                 @RequestParam(value = "pagesize",defaultValue = "10") long pagesize){
        PageResult<MomentVo> pageResult = momentService.queryFriendPublishList(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }
=======

    @Autowired
    private CommentService commentService;
    /**
     * 发布动态
     * @param vo
     * @param imageContent
     * @return
     */
    @PostMapping
    public ResponseEntity postMoment(PublishVo vo, MultipartFile[] imageContent){
        // 调用service发布
        momentService.postMoment(vo, imageContent);
        // 返回结果
        return ResponseEntity.ok(null);
    }

    /**
     * 查看好友动态
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping
    public ResponseEntity findFriendMoment(@RequestParam(value = "page",defaultValue = "1") long page,
                                           @RequestParam(value = "pagesize",defaultValue = "10") long pagesize){
        PageResult<MomentVo> pageResult = momentService.findFriendMoment(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }


    /***
     * 推荐动态
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/recommend")
    public ResponseEntity queryRecommendPublishList(@RequestParam(value = "page",defaultValue = "1") long page,
                                                    @RequestParam(value = "pagesize",defaultValue = "10") long pagesize){
        page=page<1?1:page;
        PageResult<MomentVo> pageResult = momentService.queryRecommendPublishList(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 我的动态
     * @param page
     * @param pagesize
     * @param userId
     * @return
     */
    @GetMapping("/all")
    public ResponseEntity MyMoment(@RequestParam(value = "page",defaultValue = "1") long page,
                                   @RequestParam(value = "pagesize",defaultValue = "10") long pagesize,Long userId){
        PageResult<MomentVo> pageResult = momentService.findMyMoment(page,pagesize,userId);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 点赞
     * @param publishId
     * @return
     */
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String publishId){
        Integer count = commentService.like(publishId);
        return ResponseEntity.ok(count);
    }

    /**
     * 取消点赞
     * @param publishId
     * @return
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity unlike(@PathVariable("id") String publishId){
        Integer count = commentService.unlike(publishId);
        return ResponseEntity.ok(count);
    }

    /**
     * 喜欢
     * @param publishId
     * @return
     */
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") String publishId){
        Integer count = commentService.love(publishId);
        return ResponseEntity.ok(count);
    }


    /**
     * 取消喜欢
     * @param publishId
     * @return
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") String publishId){
        Integer count = commentService.unlove(publishId);
        return ResponseEntity.ok(count);
    }

    @GetMapping("/{id}")
    public ResponseEntity oneFind(@PathVariable("id") String publishId){
        // 返回的动态信息
        if("visitors".equals(publishId)){
            return ResponseEntity.ok(null);
        }
        MomentVo momentVo = momentService.findById(publishId);
        return ResponseEntity.ok(momentVo);
    }
>>>>>>> acc7004 (第4天到第8天)
}
